package com.example.interviewdemo.myReentrantLock;

/**
 * @program my-project-model
 * @description:
 * @author: lee
 * @create: 2022/12/30 09:52
 */
public class UnReentrantLockMain {
    private NoReentrantLock noReentrantLock = new NoReentrantLock();
//ReentrantLock

    public static void main(String[] args) {
        UnReentrantLockMain unReentrantLockMain = new UnReentrantLockMain();
        unReentrantLockMain.methodA();
    }

    public void methodA() {

        try {
            noReentrantLock.lock();
            System.out.println("methodA方法被调用");
            methodB();


        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            noReentrantLock.unLock();
        }

    }

    public void methodB() {

        try {
            noReentrantLock.lock();
            System.out.println("methodB方法被调用");


        } catch (InterruptedException e) {
            e.printStackTrace();
        } finally {
            noReentrantLock.unLock();
        }

    }
}
